﻿using System;
using System.IO;
using System.Xml.Serialization;

namespace SimpleMediaManager
{
    public class Settings
    {
        public string[] SearchDirectories { get; set; }
        public bool SearchSubDirectories { get; set; }
        public string[] SearchFormats { get; set; }
        public string MovieDirectory { get; set; }
        public string MovieDirectoryStructure { get; set; }
        public bool MovieCopy { get; set; }
        public bool MovieRename { get; set; }
        public bool MovieFolder { get; set; }

        public bool VideoScale { get; set; }

        public Settings()
        {
            this.SearchFormats = new string[] { ".avi", ".mkv", ".wmv", ".mpg", ".mpeg", ".mp4", ".flv" };
            this.MovieDirectoryStructure = "<title> (<year>)";
        }

        public void Serialize(string file)
        {
            XmlSerializer serializer = new XmlSerializer(typeof(Settings));
            StreamWriter writer = File.CreateText(file);
            serializer.Serialize(writer, this);

            writer.Flush();
            writer.Close();
        }

        public static Settings Deserialize(string file)
        {
            XmlSerializer serializer = new XmlSerializer(typeof(Settings));
            StreamReader reader = File.OpenText(file);
            Settings settings = (Settings)serializer.Deserialize(reader);

            reader.Close();

            return settings;
        }
    }
}
